package cn.nexd.app.indoor.util;

import android.app.ProgressDialog;
import android.content.Context;
import android.view.View;

/**
 * com.pancou.sdk.utils
 *
 * @author ZhaoYongchun(Bruce) << zhaoyongchun@pancou.com >>
 * @version v1.0
 * @since v1.0
 */

public class ProgressDialogUtils {
    private static ProgressDialog progressDialog;
    private Context c;

    public static void showProgressDialog(Context context, String msg,
                                          String title, boolean cancel) {

        progressDialog = new ProgressDialog(context);
        // 圆形
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        if (title != null) {
            progressDialog.setTitle(title);
        }
        if (msg != null) {
            progressDialog.setMessage(msg);
        }
        progressDialog.setIndeterminate(false);
        progressDialog.setCancelable(cancel);
        progressDialog.show();
    }

    public static void showProgressDialog(Context context, String msg,
                                          String title, boolean cancel, boolean isShowProgressbar) {

        progressDialog = new ProgressDialog(context);
        // 圆形
        if (isShowProgressbar) {
            progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        }
        if (title != null) {
            progressDialog.setTitle(title);
        }
        if (msg != null) {
            progressDialog.setMessage(msg);
        }
        progressDialog.setIndeterminate(false);
        progressDialog.setCancelable(cancel);
        progressDialog.show();
    }

    public static void dismissProgressDialog(Context context) {
        if (progressDialog != null && progressDialog.isShowing()) {
            progressDialog.dismiss();
        }
    }

    /**
     * 2016.3.17 xun
     * 加载对话框可见度
     */
    public static void setProgressVisible(int visibility, Context c) {
        if (visibility == View.GONE) {
            dismissProgressDialog(c);
        } else if (visibility == View.VISIBLE) {
            showProgressDialog(c, "", "", true, false);
        }
    }

}
